local Protect_drawNcards = fk.CreateSkill {
  name = "#Protect_drawNcards",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable{
  ["#Protect_drawNcards_num>pile"] = "神临doro：%from 的摸牌数首次超过了弃牌堆数+摸牌堆数，改为摸牌堆数并获得技能【弃牌】",
  ["#Protect_drawNcards_num>20_white"] = "神临doro：%from 摸的牌实在是太多了，改为数量减半并-5",
  ["#Protect_drawNcards_num>20"] = "博丽灵梦：狐狸服专属摸牌异变！ %from 的牌实在是太多了，削弱摸牌数量",
}

local white_package_extensionName = {"shzl","standard_ex","yj","sp","ol","tenyear","mougong","mobile","mini"}

Protect_drawNcards:addEffect(fk.BeforeDrawCard, {
  mute = true,
  global = true,
  priority = 0.1,
  can_trigger = function(self, event, target, player, data)
    return target == player and data.who == player
  end,
  on_use = function(self, event, target, player, data)
    local skill = Fk.skills[data.skillName or self.name]
    local num = #player.room.draw_pile
    if data.num > num + #player.room.discard_pile then
      if not player:hasSkill("Protect_discard&", true) then
        player.room:sendLog{ type = "#Protect_drawNcards_num>pile", from = player.id, toast = true }
        data.num = num
      end
      local turn = player.room.logic:getCurrentEvent():findParent(GameEvent.Turn)
      if turn then
        if not player:hasSkill("Protect_discard&", true) then
          player.room:handleAddLoseSkills(player, "Protect_discard&", nil, true, true)
          turn:addCleaner(function()
            player.room:handleAddLoseSkills(player, "-Protect_discard&", nil, true, true)
          end)
        end
      end
    end
    if num <= 20 or data.num <= 20 then return end
    if skill and skill.package and skill.package.extensionName and table.contains(white_package_extensionName, skill.package.extensionName) then
      player.room:sendLog{ type = "#Protect_drawNcards_num>20_white", from = player.id, toast = true }
      data.num = 20
    else
      player.room:sendLog{ type = "#Protect_drawNcards_num>20", from = player.id, toast = true }
      if data.num > 20 then
        data.num = math.max(math.floor(data.num / 2) - 5, 0)
      end
    end
  end
})

return Protect_drawNcards
